import 'dart:io';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:hitutor/Util/HttpGo.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:hitutor/Util/MyColor.dart';

class LocalImage extends StatelessWidget {
  LocalImage(this.path, {this.onTap, this.width, this.height, this.padding, this.bgColor, this.fit});

  String path = "";
  void Function()? onTap;
  EdgeInsetsGeometry? padding;
  double? width;
  double? height;
  Color? bgColor;
  BoxFit? fit;

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
        onTap: onTap,
        behavior: HitTestBehavior.opaque,
        child: Container(
            decoration: BoxDecoration(color: bgColor),
            padding: padding ?? EdgeInsets.all(0),
            child: Image(
              image: AssetImage("images/" + path),
              width: width,
              height: height,
              fit: fit,
            )));
  }
}

class NetImage extends StatelessWidget {
  NetImage(this.url, {this.onTap, this.onLongTap, this.width, this.height, this.padding, this.fit = BoxFit.cover, this.radius});

  dynamic url;

  void Function()? onTap;
  void Function()? onLongTap;
  EdgeInsetsGeometry? padding;
  double? width;
  double? height;
  BoxFit fit;
  double? radius;

  @override
  Widget build(BuildContext context) {
    if (url == null) url = "";
    if (!url.startsWith("http")) {
      url = HttpGo.DO_MAIN + url;
    }
    return GestureDetector(
        onTap: onTap,
        onLongPress: onLongTap,
        behavior: HitTestBehavior.opaque,
        child: Padding(
          padding: padding ?? EdgeInsets.all(0),
          child: ClipRRect(
            borderRadius: BorderRadius.circular(radius ?? 0),
            child: CachedNetworkImage(
                imageUrl: url,
                width: width,
                height: height,
                fit: fit,
                placeholder: (i, s) {
                  return Container(color: MyColor.C5);
                }),
          ),
        ));
  }
}

class PathImage extends StatelessWidget {
  PathImage(this.path, {this.onTap, this.width, this.height, this.padding, this.fit, this.radius});

  String path = "";
  void Function()? onTap;
  EdgeInsetsGeometry? padding;
  double? width;
  double? height;
  BoxFit? fit;
  double? radius;

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
        onTap: onTap,
        behavior: HitTestBehavior.opaque,
        child: Padding(
          padding: padding ?? EdgeInsets.all(0),
          child: ClipRRect(
            borderRadius: BorderRadius.circular(radius ?? 0),
            child: Image.file(File(path), width: width, height: height, fit: fit),
          ),
        ));
  }
}

// class SvgImage extends StatelessWidget {
//   LocalImage(this.path, {this.onTap, this.width, this.height, this.padding, this.fit, this.radius});
//
//   String path = "";
//   void Function()? onTap;
//   EdgeInsetsGeometry? padding;
//   double? width;
//   double? height;
//   BoxFit? fit;
//   double? radius;
//
//   @override
//   Widget build(BuildContext context) {
//     return GestureDetector(
//         onTap: onTap,
//         behavior: HitTestBehavior.opaque,
//         child: Padding(
//             padding: padding ?? EdgeInsets.all(0),
//             child: SvgPicture.asset(
//               "images/svg/" + path,
//               width: width,
//               height: height,
//             )));
//   }
// }
